require 'spec_helper'
require 'osx/cocoa'
require 'macos/main_view'
include OSX

describe STMainView, "when created" do
  before(:each) do    
    @view = STMainView.alloc.init
    @controller = mock("GameController", :null_object => true)
    
    @view.controller = @controller
  end
  
  it "should add itself to the controller's view list" do
    @controller.views.should_receive(:<<).once.with(@view)
    
    @view.awakeFromNib
  end
  
  it "should respond to #update" do
    @view.should respond_to(:update)
  end
  
  it "should proxy #tick to the controller" do
    @controller.should_receive(:tick).once
    @view.tick
  end
  
  it "should accept first responder requests" do
    @view.acceptsFirstResponder.should == true
  end
  
  it "should set the selected object label on the selected object being changed" do
    obj = mock("GameObject")
    obj.stub!(:name).and_return("Example Object")
    
    text_field = mock("TextField")
    @view.selected_object_name = text_field
    
    text_field.should_receive(:stringValue=).once.with("Example Object")
    @view.selected_object = obj
    
    text_field.should_receive(:stringValue=).once.with("Nothing")
    @view.selected_object = nil
  end
end